import { initTree } from "../common/menuTree";

export default {
    type: 'form',
    name: 'menu-add-form',
    api: 'post:/upms/admin/menu/update',
    initApi: '/upms/admin/menu/get?id=${id}',
    messages: {
      //不展示表单失败信息
      validateFailed: ''
    },
    body: [
      {
        type: 'tabs',
        tabsMode: 'line',
        swipable: true,
        tabs:[
          {
            title: '基本信息',
            tab:[
              {
                type: 'group',
                body:[
                  {
                    type: 'input-text',
                    name: 'menuName',
                    label: '菜单名称',
                    maxLength: 50,
                    required: true,
                    validationErrors: {
                      isRequired: '请输入菜单名称'
                    }
                  },
                  {
                    type: 'input-text',
                    name: 'menuCode',
                    label: '菜单编码',
                    maxLength: 20,
                  }
                ]
              },
              {
                type: 'group',
                body:[
                  {
                    type: 'tree-select',
                    name: 'parentId',
                    label: '上级菜单',
                    source:{
                      url: '/upms/admin/menu/list/tree?systemId=${systemId}',
                      adaptor: function (payload, response, api, context) {
                          if(payload.data){
                            initTree(payload.data);
                          }
                          return {
                              ...payload
                          };
                      }
                    }
                  },
                  {
                    type: 'button-group-select',
                    name: 'type',
                    label: '菜单类型',
                    source:'/base/dict/options/menu-type',
                    value: '1',
                    required: true,
                    validationErrors: {
                      isRequired: '请选择菜单类型'
                    }
                  }
                ]
              },
              {
                type: 'group',
                body:[
                  {
                    type: 'input-text',
                    name: 'path',
                    label: '路径/路由',
                    maxLength: 100,
                  }
                ]
              },
              {
                type: 'group',
                body:[
                  {
                    type: 'input-text',
                    name: 'permission',
                    label: '权限值',
                    maxLength: 20,
                  },
                  {
                    type: 'input-tag',
                    name: 'group',
                    label: '分组',
                    maxLength: 20,
                    placeHolder: '请输入或选择分组',
                    options: [
                      '管理端',
                      '企业端'
                    ]
                  }
                ]
              },
              {
                type: 'group',
                body:[
                  {
                    type: 'switch',
                    name: 'visibleFlag',
                    label: '是否显示',
                    value: '1',
                    trueValue: 1,
                    falseValue: 0,
                    required: true,
                    validationErrors: {
                      isRequired: '请选择是否显示'
                    }
                  },
                  {
                    type: 'button-group-select',
                    name: 'openType',
                    label: '打开方式',
                    source: '/base/dict/options/open-type',
                    value: '1',
                    required: true,
                    validationErrors: {
                      isRequired: '请选择打开方式'
                    }
                  },
                  {
                    type: 'hidden',
                    name: 'systemId'
                  },
                  {
                    type: 'hidden',
                    name: 'id'
                  }
                ]
              },
              {
                type: 'group',
                body:[
                  {
                    type: 'input-number',
                    name: 'sortNo',
                    label: '排序号',
                    value: '0',
                    max: 999999,
                    min: 0,
                    maxLength: 6,
                    required: true,
                    validationErrors: {
                      isRequired: '请输入排序号'
                    }
                  },
                  {
                    type: 'input-group',
                    label: '图标',
                    body: [
                      {
                        type: 'input-text',
                        name: 'icon',
                        label: '图标',
                      },
                      {
                        type:'button',
                        actionType: 'dialog',
                        label: '选择',
                        dialog:{
                          title: '图标选择',
                          size: 'full',
                          body:{
                            type: 'iframe',
                            src: 'https://fontawesome.dashgame.com/',
                            height: '580px'
                          }
                        }
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            title: 'amis配置',
            tab:[
              {
                type: 'input-text',
                name: 'amisSchemaApi',
                label: 'schemaApi',
                maxLength: 100,
              },
              {
                type: 'textarea',
                name: 'amisSchema',
                label: 'schema',
                minRows: 12
              }
            ]
          }
        ]
      }
    ]
  }